<template v-title data-title="登陆">
  <div >
    <HeadContainer></HeadContainer>
    <div class="passport-wrapper">
      <div class="container">
        <div class="passport-sign">
          <div class="active">登录蜗牛学堂</div>
          <!-- tab-group -->
          <div class="tab-group">
            <div  class="passport-form passport-form-sign" id="regUser">
              <div class="form-item">
                <i class="phone-icon"></i>
                <input type="text" :value="loginVo.mobile" class="passport-txt xl w-full" placeholder="请输入手机号">
              </div>
              <div class="form-item form-mcode">
                <i class="yzm-icon"></i>
                <input type="password"  :value="loginVo.password" class="passport-txt xl w-full" placeholder="请输入密码">
              </div>
              <div class="form-item">
                <button type="submit" @click="login"  class="passport-btn">立即登录</button>
              </div>
            </div>
          </div>
          <!-- tab-group End -->
        </div>
      </div>
    </div>
    <FooterContainer></FooterContainer>
  </div>
</template>
<script>
import HeadContainer from '@/views/HeadContainer'
import FooterContainer from '@/views/FooterContainer'
import user from "@/api/user";
export default {
  name: "login",
  /*把导入的组件注册为一个标签*/
  components:{HeadContainer,FooterContainer},
  data(){
    return{
      loginVo: {
        mobile: '18566554433',
        password: '123456'
      },
      redirect: ''
    }
  },
  methods: {
    login(){
      user.loginApi(this.loginVo).then(data => {
        if(data.code == "200") {
          //登陆成功把token放到localStorage中
          localStorage.setItem("token", data.data);
          if(this.redirect) {
            //如果是从其他页面跳转过来的，那么登陆成功需要在跳转回去
            this.$router.push({path: this.redirect})
          }else{
            this.$router.push('/')
          }
        }
      }).catch(data => {
        console.log(data)
      });
    }
  },
  created() {
    // if (this.$route.params && this.$route.params.redirect) {
    //   this.redirect = this.$route.params.redirect;
    //   console.log("进入到登陆页面的上一个页面路径：", this.redirect)
    // }
  }
}
</script>

<style src="@/assets/css/passport-rew.min.css" scoped>

</style>